package com.example.base.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.base.bean.Mine;
import com.example.base.R;

import java.util.List;

public class MineAdapter extends ArrayAdapter<Mine> {
  Context context;
  int resource;
  List<Mine> objects;

  public MineAdapter(Context context, int resource, List<Mine> objects) {
    super(context, resource, objects);
    this.context = context;
    this.resource = resource;
    this.objects = objects;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view;
    ImageView img_left;
    TextView tv_title;
    TextView tv_text;


    if (convertView != null) {
      view = convertView;
    } else {
      view = LayoutInflater.from(context).inflate(resource, null);
    }
    img_left = view.findViewById(R.id.img_left);
    tv_title = view.findViewById(R.id.tv_title);
    tv_text = view.findViewById(R.id.tv_text);
    img_left.setImageResource(objects.get(position).getResourceId());
    tv_title.setText(objects.get(position).getTitle());
    tv_text.setText(objects.get(position).getText());

    return view;
  }
}
